package com.example.demo.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * @Author :蕉绿
 * @Date : 2023/3/7 20:56
 * @Version : V1.0
 * @Description :
 */
@ResponseBody
@ControllerAdvice
public class MyExHandler {

    @ExceptionHandler(NullPointerException.class)
    public HashMap<String ,Object> nullException(NullPointerException e) {
        HashMap<String ,Object> result = new HashMap<>();
        result.put("code","-1");
        result.put("msg","空指针异常"+e.getMessage());
        result.put("data","null");
        return result;
    }



}
